﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Raven.Imports.Newtonsoft.Json;
using Raven.Imports.Newtonsoft.Json.Converters;

namespace Rabbit.Logic
{

    public class Product
    {
        public string ShopId { get; set; }
        public string Id { get; set; }
        public string Name { get; set; }
        public decimal PricePerUnit { get; set; }
        public decimal NetWeight { get; set; }
        public decimal GrossWeight { get; set; }

        [JsonProperty(ItemConverterType = typeof(JavaScriptDateTimeConverter))]
        public DateTime? ProductionDate { get; set; }


        public DateTime? LastModifiedDate { get; set; }

        //obsoluted deprecated
        public int Quantity { get; set; }

        public string MainImage { get; set; }
        public string Title { get; set; }
        public string SubTitle { get; set; }

        public string Description { get; set; }

        //public object Chef { get; set; }
        //public object Category { get; set; }

        //public int UnitsInStock { get; set; }
        //public int UnitsOnOrder { get; set; }
        //public bool Discontinued { get; set; }
        //public int ReorderLevel { get; set; } 
    }

    public class ProductSnap
    {
        public string Id { get; set; }
        public string SnapIndex { get; set; }
        public string ShopId { get; set; }
        public string ProductId { get; set; }
        public string Name { get; set; }
        public decimal PricePerUnit { get; set; }
        public decimal NetWeight { get; set; }
        public decimal GrossWeight { get; set; }

        [JsonProperty(ItemConverterType = typeof(JavaScriptDateTimeConverter))]
        public DateTime? ProductionDate { get; set; }

        public DateTime? LastModifiedDate { get; set; }

        public string MainImage { get; set; }
        public string Title { get; set; }
        public string SubTitle { get; set; }

        public string Description { get; set; }

    }

    public class ProductSnapWithQuantity
    {
        public ProductSnap Product { get; set; }

        public int Quantity { get; set; }
    }

    public class ProductDetail
    {
        public string ProductId { get; set; }
        public string Description { get; set; }
    }

    public class ProductComment
    {
        public string ProductId { get; set; }
        public string ProductCommentId { get; set; }


        public DateTime ProductCommentDate { get; set; }
        public DateTime LastModifiedDate { get; set; }

        public string Title { get; set; }
        public string Content { get; set; }
        public string CustomerId { get; set; }

        public List<ProductCommentReply> ReplyList { get; set; }
    }

    public class ProductCommentReply
    {
        public string ProductId { get; set; }
        public string ProductCommentId { get; set; }


        public DateTime ProductCommentDate { get; set; }
        public DateTime LastModifiedDate { get; set; }

        public string Title { get; set; }
        public string Content { get; set; }
        public string CustomerId { get; set; }

        public List<Order> ReplyList { get; set; }
    }


    public class Address
    {
        public string Id { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string Detail { get; set; }
        public string PostalCode { get; set; }
        public string ContactName { get; set; }
        public string ContactPhone { get; set; }
    }

    public class AddressSnap
    {
        public string Id { get; set; }
        public string Province { get; set; }
        public string City { get; set; }
        public string Region { get; set; }
        public string Detail { get; set; }
        public string PostalCode { get; set; }
        public string ContactName { get; set; }
        public string ContactPhone { get; set; }
    }

    public class Customer
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Password { get; set; }
        public string CellPhone { get; set; }
        public string Mail { get; set; }
        public int TotalScore { get; set; }

        public List<Address> AddressList { get; set; }
        public int DefaultAddressIndex { get; set; }
        public bool IsNear { get; set; }

        //obsolete
        public List<Order> OrderList { get; set; }

        public List<Product> FavorateList { get; set; }

        public List<ShopCartItem> Cart { get; set; }
        public List<ShopItem> ShopList { get; set; }

        public ShopItem PreOrderShopItem { get; set; }

        public string OrderMappingId { get; set; }
    }

    public class CustomerOrderMapping
    {
        public string Id { get; set; }
        public string CustomerId { get; set; }
        public List<string> OrderIdList { get; set; }
        
    }

    //search by order id, state, customerId
    public class ShopOrderMapping
    {
        public string Id { get; set; }
        public string ShopId { get; set; }
        public List<string> OrderIdList { get; set; }
        public List<string> OrderIdListNew { get; set; }
        public List<string> OrderIdListSent { get; set; }
        public List<string> OrderIdListDone { get; set; }
    }

    public class ShopItem
    {
        public string ShopId { get; set; }
        public List<ShopCartItem> CartItemList { get; set; }
        public int ShipCompanyIndex { get; set; }
    }
    public class ShopItemFull
    {
        public Shop ShopInfo { get; set; }
        public List<ShopCartItemFull> CartItemList { get; set; }
    }

    //deprecated
    public class ShopCartViewItem
    {
        public ShopCartItem ItemInfo { get; set; }
        public Product ProductInfo { get; set; }
    }
    public class GroupShopCartViewItem
    {
        public ShopCartItem ItemInfo { get; set; }
        public Product ProductInfo { get; set; }
    }

    public class ShopCartItemFull
    {
        public Product ProductInfo { get; set; }
        public int Quantity { get; set; }
    }
    public class ShopCartItem
    {
        public string ProductId { get; set; }
        public int Quantity { get; set; }
    }
    public class OrderCartItem
    {
        public string ProductId { get; set; }
        public int Quantity { get; set; }
        public string ProductName { get; set; }
        public decimal PricePerUnit { get; set; }
        public decimal PriceSum { get; set; }
    }

    public class ProductSnapItem
    {
        public string ProductSnapId { get; set; }
        public int Quantity { get; set; }
    }

    public class Discount
    {
        public string Reason { get; set; }
        public decimal Rebate { get; set; }
    }
    public class Shipment
    {
        public string CompanyName { get; set; }
        public string ShipOrderId { get; set; }
        //public decimal Price { get; set; }
        public DateTime ShippedAt { get; set; }
        public string Tracking { get; set; }
    }
    public class CartTotal
    {
        public int TotalNumber { get; set; }
        public decimal TotalWeight { get; set; }
        public decimal TotalPrice { get; set; }
    }
    
    public enum OrderState
    {
        [Description("待付款")]
        WaitPayment,
        
        [Description("已付款")]
        Paid,

        [Description("待发货")]
        WaitPackage,

        [Description("已发货")]
        Sent,

        [Description("已完成")]
        Confirmed,

        [Description("已取消")]
        Canceled,

        //[Description("已签收")]
        //Received,
    }

    public enum OrderStateShop
    {
        [Description("待处理")]
        WaitProcess,
        
        [Description("已发货")]
        Sent,

        [Description("已完成")]
        Finished,
    }

    public enum PaymentType
    {
        [Description("预付款")]
        PrePaymentNetwork,

        [Description("到付现金")]
        AfterDiliveryCash,

        [Description("到付刷卡")]
        AfterDiliveryPos,
    }

    public class Order
    {
        public string Id { get; set; }
        public string CustomerId { get; set; }
        public string ShopId { get; set; }
        public Address ShipTo { get; set; }
        public PaymentType PayType { get; set; }

        public List<ProductSnapItem> Items { get; set; }
        
        public Discount[] Discounts { get; set; }
        public CartTotal Total { get; set; }
        public decimal DiliveryPrice { get; set; }
        public decimal FinalPrice { get; set; }

        public DateTime OrderedAt { get; set; }
        public DateTime RequireAt { get; set; }

        public DateTime PayedAt { get; set; }

        public OrderState State { get; set; }
        public Shipment ShipmentInfo { get; set; }

        public DateTime FinishedAt { get; set; }

        public string OrderLogId { get; set; }
    }

    public class OrderLog
    {
        public string Id { get; set; }
        public string OrderId { get; set; }
        public List<string> LogList { get; set; } 
    }

    //public class OrderWithProductSnapWithQuantity
    //{
    //    public Order OrderInfo { get; set; }

    //    public List<ProductSnapWithQuantity> ProductSnapWithQuantityList { get; set; }
    //}

    public class OrderViewCustomer
    {
        public Order OrderInfo { get; set; }
        public Shop ShopInfo { get; set; }

        public List<ProductSnapWithQuantity> ProductSnapWithQuantityList { get; set; }
    }

    public class OrderViewShop
    {
        public Order OrderInfo { get; set; }
        public Customer CustomerInfo { get; set; }

        public List<ProductSnapWithQuantity> ProductSnapWithQuantityList { get; set; }
    }

    public class DiliveryCompany
    {
        public string Id { get; set; }
        public int Index { get; set; }
        public string CompanyName { get; set; }
        public string TrackingUrl { get; set; }
        //public decimal BasePrice { get; set; }
        //public decimal KgPrice { get; set; }
        public string OfficalSite { get; set; }
        public string ServiceTel { get; set; }
    }

    public class DiliveryStrategy
    {
        public string Id { get; set; }
        public string ShopId { get; set; }
        public decimal Cost { get; set; }
        public string StrategyName { get; set; }
        public List<string> CityList { get; set; }
        public List<string> ProvinceList { get; set; }
        public decimal GreaterThan { get; set; }
    }

    public class ShipRule
    {
        public string Id { get; set; }
        public string ShopId { get; set; }
        public Dictionary<string, decimal> Rules { get; set; }
        public Dictionary<string, decimal> CityRules { get; set; }
        public List<string> CommunityList { get; set; }
    }

    public class DiliveryPriceResult
    {
        public string Reason { get; set; }
        public decimal Price { get; set; }
    }

    public class RegionCost
    {
        public string Region { get; set; }
        public decimal Cost { get; set; }
    }

    public class ShipDiscount
    {
        public string Id { get; set; }
        public string ShopId { get; set; }
        public decimal FreeShipAt { get; set; }
    }

    public class ShopIdentity
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public string Password { get; set; }
        public string CellPhone { get; set; }
        public string Mail { get; set; }
    }

    public class Shop
    {
        public string Id { get; set; }
        public string ShopId { get; set; }
        public string Name { get; set; }
        public string Password { get; set; }
        public string CellPhone { get; set; }
        public string Mail { get; set; }

        public bool IsCertified { get; set; }

        public Address Location { get; set; }
        public string LicenceName { get; set; }
        public string LicenceId { get; set; }
        public LawMan Owner { get; set; }
        public string Tel { get; set; }
        public DateTime JoinDate { get; set; }

        public string NickName { get; set; }
        public string DiliveryCostDescription { get; set; }
        public decimal FreeShipAt { get; set; }

        public string OrderMappingId { get; set; }
        public List<Discount> Discounts { get; set; } 
    }

    public class ShopStatistics
    {
        public string ShopId { get; set; }
        public List<DiliveryStrategy> DiliveryStrategyList { get; set; }
        public List<int> ProductList { get; set; } 
    }

    public class LawMan
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string CardNo { get; set; }
        public bool Sex { get; set; }

    }
}
